package cn.edu.jxau.core.vo;

import cn.edu.jxau.core.util.upload.FileUpload;

import java.io.File;
import java.io.Serializable;
import java.util.List;

/**
 * 光谱文件类型
 *
 * @author 巫发萍
 * PretreatmentAlgorithm
 * 2017年8月9日
 */

public class SpectrumFile implements Serializable {
    /**
     * 序列化id
     */
    private static final long serialVersionUID = -7414430695439357006L;
    // 表单需要
    private String spectrumName;// 光谱名称,如 敌敌畏
    private String spectrumType; // 光谱类型名称,比如拉曼
    private String xAsix;// 光谱x轴单位,不为空,默认 波数
    private String yAsix;// 光谱y轴单位,不为空,默认 吸光度

    private List<Point> points;// 光谱数据点

    private Double minY = Double.MAX_VALUE;// 最小Y值
    private Double maxY = Double.MIN_VALUE;// 最大Y值
    private Point minPeaks;// 最小峰谷点
    private Point maxPeaks;// 最大峰值点

    private String fileDir; // 文件相对路径  WEB-INF/data/spectrum/2017/9/8
    private String fileName; // 文件名  三唑磷.txt

    /**
     * 对象特征自刷新，依照List<pints>
     */
    public void flush() {
        if (points == null || 0 == points.size()) return;
        minPeaks = points.get(0);
        maxPeaks = minPeaks;
        minY = minPeaks.getY();
        maxY = minY;
        for (Point point : points) {
            if (point.getY() > maxY) {
                maxY = point.getY();
                maxPeaks = point;
            }
            if (point.getY() < minY) {
                maxY = point.getY();
                minPeaks = point;
            }
        }
    }

    /**
     * 得到文件的绝对路径
     * @return
     */
    public String getABSPath(){
        return new File(new File(FileUpload.getBaseABSPath(), fileDir), fileName).getAbsolutePath();
    }

    public String getSpectrumName() {
        return spectrumName;
    }


    public void setSpectrumName(String spectrumName) {
        this.spectrumName = spectrumName;
    }


    public String getSpectrumType() {
        return spectrumType;
    }


    public void setSpectrumType(String spectrumType) {
        this.spectrumType = spectrumType;
    }


    public String getxAsix() {
        return xAsix;
    }


    public void setxAsix(String xAsix) {
        this.xAsix = xAsix;
    }


    public String getyAsix() {
        return yAsix;
    }


    public void setyAsix(String yAsix) {
        this.yAsix = yAsix;
    }


    public Double getMinY() {
        return minY;
    }


    public void setMinY(Double minY) {
        this.minY = minY;
    }


    public Double getMaxY() {
        return maxY;
    }


    public void setMaxY(Double maxY) {
        this.maxY = maxY;
    }


    public List<Point> getPoints() {
        return points;
    }


    public void setPoints(List<Point> points) {
        this.points = points;
    }

    public Point getMaxPeaks() {
        return maxPeaks;
    }


    public void setMaxPeaks(Point maxPeaks) {
        this.maxPeaks = maxPeaks;
    }


    public Point getMinPeaks() {
        return minPeaks;
    }


    public void setMinPeaks(Point minPeaks) {
        this.minPeaks = minPeaks;
    }


    public String getFileName() {
        return fileName;
    }


    public void setFileName(String fileName) {
        this.fileName = fileName;
    }


    public String getFileDir() {
        return fileDir;
    }


    public void setFileDir(String fileDir) {
        this.fileDir = fileDir;
    }


    @Override
    public String toString() {
        return "{ \"spectrumName\": " + spectrumName
                + ", \"spectrumType\": " + spectrumType
                + ", \"xAsix\": " + xAsix
                + ", \"yAsix\": " + yAsix
                + ", \"minY\": " + minY
                + ", \"maxY\": " + maxY
                + ", \"minPeaks\": " + minPeaks
                + ", \"maxPeaks\": " + maxPeaks
                + ", \"fileName\": " + fileName
                + ", \"fileDir\": " + fileDir
//                + ", \"points\": " + points
                + "}";
    }

}
